﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;

namespace RegTreeView
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            using (RegistryKey hklm = Registry.LocalMachine)
            {
                using (RegistryKey hkcu = Registry.CurrentUser)
                {
                    var root = new ObservableCollection<RegKey>();

                    root.Add(new RegKey(hklm));
                    root.Add(new RegKey(hkcu));

                    treeReg.ItemsSource = root;
                }
            }
        }

        private void treeReg_Selected(object sender, RoutedEventArgs e)
        {
            TreeViewItem Curitem = e.OriginalSource as TreeViewItem;

            RegKey CurKey = Curitem.Header as RegKey;

            if (!CurKey.IsRegKey)
            {
                grdCurRegInfo.DataContext = CurKey;
            }
            else
            {
                grdCurRegInfo.DataContext = null;
            }

            
        }
    }
}
